/**
 * 
 */
package monitor;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.Executors;

import javax.swing.JTextArea;
import javax.swing.JTextField;

import current.DataAcquisitionThread;
import current.MultithreadProcessing;

/**
 * @Description:  
 * @version: v1.0.0
 * @author: wbl
 * @date: 2019年10月23日 下午2:41:22
 */
public class Button1Listener implements ActionListener {
	
	
    public JTextArea resultArea;//视图显示结果
    private JTextField textFieldA;//输入的边
    private JTextField textFieldB;
    private JTextField textFieldC;

	 	public void setResultArea(JTextArea resultArea) {
	        this.resultArea = resultArea;
	    }

	    public void setTextFieldA(JTextField textFieldA) {
	        this.textFieldA = textFieldA;
	    }

	    public void setTextFieldB(JTextField textFieldB) {
	        this.textFieldB = textFieldB;
	    }

	    public void setTextFieldC(JTextField textFieldC) {
	        this.textFieldC = textFieldC;
	    }

	    /**
	     * 触发该函数的只能是那一个按钮，所以不用ActionEvent去判定他的ActionCommand
	     * @param e
	     */
	    public void actionPerformed(ActionEvent e)
	    {
	    	System.out.println("按钮被点击");
	        try {
	            String code = textFieldA.getText();
	            String di = textFieldB.getText();
	            String gao =  textFieldC.getText();
	            double mon1 = 0;
	            double mon2 = 0;
	            
	            if(!di.isEmpty()) {
	            	mon1 = Double.parseDouble(textFieldB.getText());
	            }
	            if(!gao.isEmpty()) {
	            	mon2 = Double.parseDouble(textFieldC.getText());
	            }

	            resultArea.setText("");
	            DataAcquisitionThread triangle = new DataAcquisitionThread(code,mon1,mon2);
	            System.out.println("new了一个新的数据获取对象");
	            triangle.setResultArea(resultArea);
	            triangle.setTextFieldA(textFieldA);
	            triangle.setTextFieldB(textFieldB);
	            triangle.setTextFieldC(textFieldC);

	            MultithreadProcessing.recvAtuoTaskThreadPool.execute(triangle);

	        }catch (Exception exception)
	        {
	            resultArea.setText("请输入编码");
	        }

	    }

}
